﻿// ....................................................................................................................
//	Author: Copyright (C) 2012 Ing. Marek Hubal
//	Email: hubal@acasoftware.org
// ....................................................................................................................

using System;

namespace core
{
    /// <summary>Trieda IForm</summary>
	public class IForm : System.Windows.Forms.Form
	{
        protected bool FFormInitialized; // Priznak ukoncenej inicializacie formulara
        protected bool FLastMaximized; // Priznak posledneho stavu maximalizacie

        /// <summary>Property: CanCloseForm</summary>
        public virtual bool CanCloseForm
        {
            get
            {
                return true;
            }
        }

        /// <summary>Konstruktor</summary>
        public IForm()
        {
            SuspendLayout(); // Pozastavim layout
            FLastMaximized = false; // Inicializacia
            FFormInitialized = false;
        }
        /// <summary>Dispose metoda</summary>
        /// <param name="disposing">parameter</param>
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing); // Volam predchodcu
        }

        /// <summary>Vytvorenie obsahu okna</summary>
        /// <returns>true / false</returns>
        protected virtual bool OnCreateForm()
        {
            Icon = core.Properties.Resources.main_icon;
            return true; // Vsetko OK
        }
        /// <summary>Metoda: OnSizeChanged</summary>
        /// <param name="e">parameter</param>
        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e); // Volam predchodcu
            if (WindowState == System.Windows.Forms.FormWindowState.Normal) FLastMaximized = false; // Ulozim stav maximalizacie
            if (WindowState == System.Windows.Forms.FormWindowState.Maximized) FLastMaximized = true;
        }

        /// <summary>Zobrazenie okna</summary>
        public new void Show()
        {
            if (!FFormInitialized)
            {
                if (!OnCreateForm()) return; // Volam vytvorenie okna
                FFormInitialized = true;
            }
            ResumeLayout(true); // Povolim layout
            base.Show(); // Volam predchodcu
        }
        /// <summary>Zobrazenie okna</summary>
        /// <param name="owner">parameter</param>
        public new void Show(System.Windows.Forms.IWin32Window owner)
        {
            if (!FFormInitialized)
            {
                if (!OnCreateForm()) return; // Volam vytvorenie okna
                FFormInitialized = true;
            }
            ResumeLayout(true); // Povolim layout
            base.Show(owner); // Volam predchodcu
        }
        /// <summary>Zobrazenie okna</summary>
        public new System.Windows.Forms.DialogResult ShowDialog()
        {
            if (!FFormInitialized)
            {
                if (!OnCreateForm()) return System.Windows.Forms.DialogResult.Abort; // Volam vytvorenie okna
                FFormInitialized = true;
            }
            ResumeLayout(true); // Povolim layout
            return base.ShowDialog(); // Volam predchodcu
        }
        /// <summary>Zobrazenie okna</summary>
        /// <param name="owner">parameter</param>
        public new System.Windows.Forms.DialogResult ShowDialog(System.Windows.Forms.IWin32Window owner)
        {
            if (!FFormInitialized)
            {
                if (!OnCreateForm()) return System.Windows.Forms.DialogResult.Abort; // Volam vytvorenie okna
                FFormInitialized = true;
            }
            ResumeLayout(true); // Povolim layout
            return base.ShowDialog(owner); // Volam predchodcu
        } 
    }
}
